<%--
  Created by IntelliJ IDEA.
  User: 谢兴鑫
  Date: 2022/5/23
  Time: 下午 03:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/ajaxForm.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/textarea/index.min.js" ></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/textarea/normalize.min.css" rel="stylesheet">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/textarea/wangeditor.css"  rel="stylesheet">
    <title>Title</title>
</head>
<script>
    layui.use(['form','layer','jquery'],function () {
        var form=layui.form,layer=layui.layer,$=layui.jquery;
        //给表单赋值
        $(function () {
            form.val("form2",${notice});
        })

        //监听表单提交
        form.on('submit(formBtn)',function () {
            // alert("AA");
            var formData = new FormData($("#form1")[0]);
            $.ajax({
                url:'${pageContext.request.contextPath}/notice/updNotice',
                type : 'POST',
                data : formData,
                cache: false,
                async: false,
                processData : false,  //必须false才会避开jQuery对 formdata 的默认处理
                contentType : false,  //必须false才会自动加上正确的Content-Type
                success:function(data){
                    layer.msg('编辑成功！',{icon:6,offset:"auto",time:2000});//提示框
                    setTimeout(function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);//关闭弹出层
                        parent.location.reload();//重新加载父页面表格
                    }, 2100);
                }
            })
            return false;
        });

    });
</script>
<html>
<head>
    <title>Title</title>
</head>
</head>
<body>
<form class="layui-form" id="form1" lay-filter="form2">

    <div class="layui-form-item">
        <div class="layui-input-inline">
            <input type="hidden" name="noticeId" id="noticeId" placeholder="公告编号" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-inline">
            <input type="hidden" name="empId" id="empId" placeholder="员工编号" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <input type="hidden" name="noticeId" class="layui-input">
    <div class="layui-form-item">
        <label class="layui-form-label">标题:</label>
        <div class="layui-input-inline">
            <input type="text" name="title" id="title" class="layui-input" placeholder="请输入标题">
        </div>
    </div>
    <demo-nav title="wangEditor get HTML"></demo-nav>
    <div class="page-container">
        <div class="page-left">
            <demo-menu></demo-menu>
        </div>
        <div class="page-right">
            <!-- 编辑器 DOM -->
            <div style="border: 1px solid #ccc;">
                <div id="editor-toolbar" style="border-bottom: 1px solid #ccc;"></div>
                <div id="editor-text-area" style="height: 350px"></div>
            </div>

            <!-- 显示内容 -->
            <div style="margin-top: 20px;">
                <input type="hidden" id="content" name="content" style="width: 100%; height: 100px; outline: none;" readonly/>
            </div>
            <div id="editor-content-view" class="editor-content-view"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="formBtn">编辑</button>
        </div>
    </div>
</form>
<script>
    const E = window.wangEditor
    // 切换语言
    const LANG = location.href.indexOf('lang=en') > 0 ? 'en' : 'zh-CN'
    E.i18nChangeLanguage(LANG)
    window.editor = E.createEditor({
        selector: '#editor-text-area',
        html: '${notice.content}',
        config: {
            placeholder: '',
            MENU_CONF: {
                uploadImage: {
                    fieldName: 'your-fileName',
                    base64LimitSize: 10 * 1024 * 1024 // 10M 以下插入 base64
                }
            },
            onChange(editor) {
                const html = editor.getHtml()
                //   document.getElementById('editor-content-view').innerHTML = html
                document.getElementById('content').value = html
            }
        }
    })
    window.toolbar = E.createToolbar({
        editor,
        selector: '#editor-toolbar',
        config: {}
    })
</script>
</body>
</html>
